import { GetUserInfoFromLocal, SaveUserInfoToLocal } from '@/utils/storage'
import { GetUserInfoFromSrv } from '@/utils/request'

export default {
  namespaced: true,
  state () {
    return {
      userInfo: GetUserInfoFromLocal()
    }
  },
  mutations: {
    setUserInfo (state, info) {
      state.userInfo = info
      SaveUserInfoToLocal(info)
    }
  },
  actions: {
    async asyncUpdateUserInfoFromSrv (context) {
      const res = await GetUserInfoFromSrv()
      context.commit('setUserInfo', res)
    },
    logout (context) {
      context.commit('setUserInfo', {})
    }
  },
  getters: {

  }
}
